package com.dz.lm.service.comment.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dz.lm.common.dto.CommentDTO;
import com.dz.lm.common.exception.DaoException;
import com.dz.lm.common.exception.ServiceException;
import com.dz.lm.domain.comment.Comment;
import com.dz.lm.service.AbstractService;
import com.dz.lm.service.comment.CommentService;


@Service
public class CommentServiecImpl  extends AbstractService implements CommentService {
	
	
	@Resource(name="readCommentDao")
	private com.dz.lm.dao.comment.read.CommentDao readCommentDao;
	
	@Resource(name="writeCommentDao")
	private com.dz.lm.dao.comment.write.CommentDao writeCommentDao;

	@Override
	public List<CommentDTO> ListComment() throws ServiceException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public CommentDTO selectByPrimaryKey(Integer CommentId) throws ServiceException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int insert(Map<String, Object> param) throws ServiceException {
		try {
			return writeCommentDao.insert(param);
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
	}

	@Override
	public int delete(Map<String, Object> param) throws ServiceException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Map<String, Object> qryProductCommentList(Map<String, Object> param) throws ServiceException {
		Map<String, Object> retMap = new HashMap<String, Object>();
		List<Map<String, Object>> productCommentList = null;
		List<Map<String, Object>> agentProductCommentList = null;
		try {
			if (param.get("productId") != null) {
				productCommentList = readCommentDao.qryCommentsByProductId(param);
			} else {
				agentProductCommentList = readCommentDao.qryCommentsByAgentProductId(param);
			}
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		retMap.put("productCommentList", productCommentList);
		retMap.put("agentProductCommentList", agentProductCommentList);
		return retMap;
	}

}
